package com.education.welco.service.impl;

import com.education.common.pojo.AjaxResult;
import com.education.welco.mapper.SysAppVersionServiceMapper;
import com.education.welco.pojo.SysAppVersion;
import com.education.welco.service.SysAppVersionService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @Author: liftsail
 * @Date: 2023/2/1 10:34
 * @Description: 不积跬步无以至千里
 */
@Service
public class SysAppVersionServiceImpl implements SysAppVersionService {

    @Autowired
    private SysAppVersionServiceMapper sysAppVersionServiceMapper;

    @Override
    public AjaxResult addAppVersion(SysAppVersion sysAppVersion) {
        sysAppVersion.settCreateTime(new Date());
        if(sysAppVersionServiceMapper.insertSelective(sysAppVersion)>0) return AjaxResult.success("添加成功");
        return AjaxResult.error("添加失败");
    }

    @Override
    public AjaxResult delAppVersion(SysAppVersion sysAppVersion) {
        if(sysAppVersionServiceMapper.deleteByPrimaryKey(sysAppVersion.getId())>0) return AjaxResult.success("删除成功");
        return AjaxResult.error("删除失败");
    }

    @Override
    public AjaxResult appVersionList(SysAppVersion sysAppVersion) {
        PageHelper.startPage(sysAppVersion.getPageNum(), sysAppVersion.getPageSize());
        List list = sysAppVersionServiceMapper.getSysAppVersionList(sysAppVersion);
        PageInfo pageInfo = new PageInfo<>(list);
        return AjaxResult.success("data",pageInfo);
    }

    /**
     * app查询最新一条版本记录
     */
    @Override
    public SysAppVersion getLatSysAppVersion() {
        return sysAppVersionServiceMapper.getLatSysAppVersion();
    }
}

